<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>bind</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4>NAME</h4><blockquote>
bind - bind a name to a socket
</blockquote><h4>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="syssocket.h.html">sys/socket.h</a>&gt;

int bind(int <I>socket</I>, const struct sockaddr *<I>address</I>,
     socklen_t <I>address_len</I>);
</code>
</pre>
</blockquote><h4>DESCRIPTION</h4><blockquote>
The
<i>bind()</i>
function assigns an <I>address</I> to an unnamed socket.  Sockets created with
<i><a href="socket.html">socket()</a></i>
function are initially unnamed; they are identified only by their address
family.
<p>
The function takes the following arguments:
<dl compact>

<dt><I>socket</I><dd>Specifies the file descriptor of the socket to be bound.

<dt><I>address</I><dd>Points to a <B>sockaddr</B> structure containing the address to be bound to the
socket.  The length and format of the address depend on the address family of
the socket.

<dt><I>address_len</I><dd>Specifies the length of the <B>sockaddr</B> structure pointed
to by the <I>address</I> argument.

</dl>
<p>
The socket in use may require the process to have appropriate
privileges to use the
<i>bind()</i>
function.
</blockquote><h4>RETURN VALUE</h4><blockquote>
Upon successful completion,
<i>bind()</i>
returns 0.  Otherwise, -1 is returned and <I>errno</I> is set to
indicate the error.
</blockquote><h4>ERRORS</h4><blockquote>
The
<i>bind()</i>
function will fail if:
<dl compact>

<dt>[EADDRINUSE]<dd>The specified address is already in use.

<dt>[EADDRNOTAVAIL]<dd>The specified address is not available from the local machine.

<dt>[EAFNOSUPPORT]<dd>The specified address is not a valid address for the address family of the
specified socket.

<dt>[EBADF]<dd>The <I>socket</I> argument is not a valid file descriptor.

<dt>[EFAULT}<dd>The 
<I>address</I>
argument can not be accessed.

<dt>[EINVAL]<dd>The socket is already bound to an address, and the protocol does not
support binding to a new address;
or the socket has been shut down.

<dt>[ENOTSOCK]<dd>The <I>socket</I> argument does not refer to a socket.

<dt>[EOPNOTSUPP]<dd>The socket type of the specified socket does not support binding to an
address.

</dl>
<p>
If the address family of the socket is AF_UNIX, then
<i>bind()</i>
will fail if:
<dl compact>

<dt>[EACCES]<dd>A component of the path prefix denies search permission, or the requested name
requires writing in a directory with a mode that denies write permission.

<dt>[EDESTADDRREQ] or [EISDIR]<dd><br>
The <I>address</I> argument is a null pointer.

<dt>[EIO]<dd>An I/O error occurred.

<dt>[ELOOP]<dd>Too many symbolic links were encountered in translating the pathname in
<I>address.</I>

<dt>[ENAMETOOLONG]<dd>A component of a pathname exceeded {NAME_MAX} characters, or an entire
pathname exceeded {PATH_MAX} characters.

<dt>[ENOENT]<dd>A component of the pathname does not name an existing file
or the pathname is an empty string.

<dt>[ENOTDIR]<dd>A component of the path prefix of the pathname in <I>address</I> is
not a directory.

<dt>[EROFS]<dd>The name would reside on a read-only filesystem.

</dl>
<p>
The
<i>bind()</i>
function may fail if:
<dl compact>

<dt>[EACCES]<dd>The specified address is protected and the current user does not
have permission to bind to it.

<dt>[EINVAL]<dd>The <I>address_len</I> argument is not a valid length for the address family.

<dt>[EISCONN]<dd>The socket is already connected.

<dt>[ENAMETOOLONG]<dd>Pathname resolution of a symbolic link produced an intermediate result whose
length exceeds {PATH_MAX}.

<dt>[ENOBUFS]<dd>Insufficient resources were available to complete the call.

<dt>[ENOSR]<dd>There were insufficient STREAMS resources for the operation to complete.

</dl>
</blockquote><h4>APPLICATION USAGE</h4><blockquote>
An application program can retrieve the assigned socket name with the
<i><a href="getsockname.html">getsockname()</a></i>
function.
</blockquote><h4>SEE ALSO</h4><blockquote>
<i><a href="connect.html">connect()</a></i>,
<i><a href="getsockname.html">getsockname()</a></i>,
<i><a href="listen.html">listen()</a></i>,
<i><a href="socket.html">socket()</a></i>,
<i><a href="syssocket.h.html">&lt;sys/socket.h&gt;</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
